package org.example.bean;

/**
 * 双重校验锁-线程安全
 * @author: yh
 * @date: 2022/12/11
 */
public class SingletonBothLock {
    private volatile static SingletonBothLock uniqueInstance;

    private SingletonBothLock() {
    }

    public static SingletonBothLock getUniqueInstance() {
        if (uniqueInstance == null) {
            synchronized (SingletonBothLock.class) {
                // 一定要双重if
                if (uniqueInstance == null) {
                    uniqueInstance = new SingletonBothLock();
                }
            }
        }
        return uniqueInstance;
    }
}
